package com.hongxun.modules.eys.service.impl;

import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.hongxun.modules.eys.dao.EPointDao;
import com.hongxun.modules.eys.entity.EPointEntity;
import com.hongxun.modules.eys.service.EPointService;



@Service("ePointService")
public class EPointServiceImpl implements EPointService {
	@Autowired
	private EPointDao ePointDao;
	
	@Override
	public EPointEntity queryObject(String guid){
		return ePointDao.queryObject(guid);
	}
	
	@Override
	public List<EPointEntity> queryList(Map<String, Object> map){
		return ePointDao.queryList(map);
	}
	
	@Override
	public int queryTotal(Map<String, Object> map){
		return ePointDao.queryTotal(map);
	}
	
	@Override
	public void save(EPointEntity ePoint){
        if(ePoint.getGuid()==null||ePoint.getGuid().equals("")) {

		    ePoint.setGuid(UUID.randomUUID().toString());
        }
		ePointDao.save(ePoint);
	}
	
	@Override
	public void update(EPointEntity ePoint){
		ePointDao.update(ePoint);
	}
	
	@Override
	public void delete(String guid){
		ePointDao.delete(guid);
	}
	
	@Override
	public void deleteBatch(String[] guids){
		ePointDao.deleteBatch(guids);
	}

	@Override
	public void insertOrReplaceOrDelete(List<EPointEntity> entities) {
		for (EPointEntity d : entities) {
			if (d.getPPDatastate().equals("删除")) {
				ePointDao.delete(d.getGuid());
			} else {
				EPointEntity ePointEntity = ePointDao.queryObject(d.getGuid());
				if (ePointEntity == null) {
					ePointDao.save(d);
				} else {
					ePointDao.update(d);
				}
			}
		}
	}
	
}
